We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.

Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)

Bug 3392947 - Using %define with existing empty define's name made of a context-local prefix and a macro indirection suffix fails, works for non-context-local prefix
Summary: Using %define with existing empty define's name made of a context-local prefi...
Status: OPEN
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 2.16.xx
Hardware: All All
: Medium normal
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2025-08-09 02:54 PDT by E. C. Masloch
Modified: 2025-08-09 02:54 PDT (History)
4 users (show)

Obtained from: Built from git using configure
Generated by: Human
Bug category: Incorrect main output, Unexpected or confusing behavior
Observed for: Valid test code
Regression: No
Regression since:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description E. C. Masloch 2025-08-09 02:54:47 PDT
Expectation: All cases should work and display bar or qux. Actual result: If a context-local define is defined to the empty token, and then we attempt to re-define it using either %define or %xdefine in which we build the define name using macro indirection %[...], it fails with "error: `%xdefine' expects a macro identifier". The same for a non-context-local smacro define works as expected.

Test case:

test$ nasm -v
NASM version 2.16.02rc2 compiled on Oct 12 2023
test$ cat test.asm
%assign slot 26
%push

%ifdef INIT
%define %$entry26
%define entry26
%endif

%define foo bar
%ifdef A
 %define %$entry%[slot] foo
%elifdef B
 %xdefine %$entry%[slot] foo
%elifdef C
 %define entry%[slot] foo
%elifdef D
 %xdefine entry%[slot] foo
%endif
%define foo qux
%fatal %$entry26 entry26
test$ nasm test.asm -DA
test.asm:20: fatal: qux entry26
test$ nasm test.asm -DB
test.asm:20: fatal: bar entry26
test$ nasm test.asm -DC
test.asm:20: fatal: %$entry26 qux
test$ nasm test.asm -DD
test.asm:20: fatal: %$entry26 bar
test$ nasm test.asm -DINIT -DA
test.asm:11: error: `%define' expects a macro identifier
test.asm:20: fatal:
test$ nasm test.asm -DINIT -DB
test.asm:13: error: `%xdefine' expects a macro identifier
test.asm:20: fatal:
test$ nasm test.asm -DINIT -DC
test.asm:20: fatal: qux
test$ nasm test.asm -DINIT -DD
test.asm:20: fatal: bar
test$


I came across this during development of a partitioning script I wrote using NASM, in which I wanted to re-define one of four different context-local variables addressed using a 1 to 4 suffix. I eventually solved this differently which works here because I only needed 4 different conditional branches. The work around code in question is at https://hg.pushbx.org/ecm/bootimg/file/708fd9e7617a/partdisk.asm#l427